/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef __XMLHANDLER_HDR__
#define __XMLHANDLER_HDR__


#include <xercesc/sax2/DefaultHandler.hpp>
#include <stdexcept>
#include <string>

namespace logging{

	/*!
	 */
	class Logger;

};

namespace xml{

	/*!
	 */
	class Document;


	/*!
	 * \struct atc::xmlhandler_error
	 */
	struct xmlhandler_error : public std::runtime_error{
		xmlhandler_error(const std::string& msg) 
			:std::runtime_error(msg){}
	};


	/*!
	 * \class atc::XMLHandler atc_xmlhandler.h
	 */
	class XMLHandler : public xercesc::DefaultHandler
	{
	public:
	       
		XMLHandler(xml::Document&, logging::Logger*);
		virtual ~XMLHandler();

		//
		// SAX DocumentHandler interface
		//
        void startElement(
            const   XMLCh* const    uri,
            const   XMLCh* const    localname,
            const   XMLCh* const    qname,
            const   xercesc::Attributes&     attrs
        );
        void endElement(
            const   XMLCh* const    uri,
            const   XMLCh* const    localname,
            const   XMLCh* const    qname
        );
        void characters(
            const XMLCh* const chars,
            const XMLSize_t length
        );


		//
		// SAX ErrorHandler Interface
		//

		void warning(const xercesc::SAXParseException &);
		void error(const xercesc::SAXParseException &);
		void fatalError(const xercesc::SAXParseException &);

	private:

		std::string error_text(const xercesc::SAXParseException &);


	private:

		xml::Document &_document;
		logging::Logger* _logger;

		std::string _buffer;


	};
	
}; 

#endif 
